package com.ruicar.afs.cloud.basic.caseInterface.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruicar.afs.cloud.basic.caseInterface.condition.BasicLoanAmountCondition;
import com.ruicar.afs.cloud.basic.caseInterface.mapper.BasicLoanAmountMapper;
import com.ruicar.afs.cloud.basic.caseInterface.service.BasicLoanAmountService;
import com.ruicar.afs.cloud.basic.caseInterface.vo.BasicExternalLoanAmountVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @description: 聚合历史贷款金额
 * @author jiaqi.guo
 * @created 2020/10/10 18:45
 * @version 1.0
 */
@Service
@Slf4j
public class BasicLoanAmountServiceImpl extends ServiceImpl<BasicLoanAmountMapper, BasicExternalLoanAmountVo> implements BasicLoanAmountService {
    /**
     * 根据 共借人和主借人证件号码查询
     */
    public List<BasicExternalLoanAmountVo> getLoanAmountHistory(String borrowerCertno, String coborrowerCertno) {
        BasicLoanAmountCondition amountCondition = new BasicLoanAmountCondition();
        //证件号码
        List<String> certNoList = new ArrayList<>();
        certNoList.add(borrowerCertno);
        certNoList.add(coborrowerCertno);
        amountCondition.setCertNoList(certNoList);
        List<BasicExternalLoanAmountVo> list = this.baseMapper.getLoanAmountHistory(amountCondition);
        List<BasicExternalLoanAmountVo> amountVoList = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(list)) {
            for (BasicExternalLoanAmountVo amountVo : list) {
                BasicExternalLoanAmountVo loanAmountVo = new BasicExternalLoanAmountVo();
                BeanUtil.copyProperties(amountVo,loanAmountVo);
                amountVoList.add(loanAmountVo);
            }
            log.info("历史贷款金额有返回结果" + list.size());
        } else {
            log.info("历史贷款金额无返回结果");
        }

        return amountVoList;
    }
}
